<template>
  <el-row style="padding: 0px 20%;">
    <el-row style="background-color: rgb(255, 251, 240);" class="border">
      <el-col
        :sm="24"
        style="text-align:center;font-size: 24px;font-weight: 700;padding: 10px 0;color: #CD2824;"
      >
        <div>{{this.articleData.title}}</div>
      </el-col>
      <el-col :sm="24" style="text-align:center;padding: 10px 10%;">
        <div class="xl_fenge"></div>
      </el-col>

      <el-col
        :sm="24"
        style="font-size: 12px;
    color: #000000;
    line-height: 25px;
    text-align: center;
    padding-bottom: 12px;"
      >
        <div>发布时间为{{this.articleData.createtime}}</div>
      </el-col>
      <el-col
        :sm="24"
        style="text-align:center;font-size: 30px;font-weight: normal;padding: 10px 0;font-family: 方正小标宋简体;color: #000000"
      >
        <div>{{this.articleData.title}}</div>
      </el-col>
      <el-col
        :sm="24"
        style="text-align:left;padding: 10px 10%;font-family: 仿宋_GB2312;
    font-size: 16pt;"
        v-show="this.textVisible== true"
        class="dialog-content"
      >
        <div
          class="textdetails"
          v-html="this.articleData.textdetails"
        >{{this.articleData.textdetails}}</div>
      </el-col>
      <el-col :sm="24" style="padding: 10px 10%;">
        <div style="border-bottom: 1px dashed #B36670;"></div>
      </el-col>
      <el-col :sm="24" style="text-align:left;padding: 10px 10%;" v-show="this.titleNode== true">
        <div>{{this.articleData.simpledetails}}</div>
      </el-col>
      <el-col
        :sm="24"
        style="text-align:left;font-size: 19px;padding: 10px 10%;color:red;"
        v-show="this.urlVisble == true"
      >
        <div @click=" toDocument">
          <el-link type="danger" :underline="false">【附件下载】</el-link>
        </div>
        <el-col
          :sm="24"
          style="text-align:left;padding: 10px 0;"
          v-show="this.articleData.document"
        >
          <el-link type="info" style="font-size: 14px;padding: 10px 0;color:red;">【上传附件】</el-link>
          <div>
            <el-upload
              class="upload-demo"
              drag
              :action="uploadUrl"
              multiple
              :on-success="handleAvatarSuccess"
              ref="ersty"
              :on-error="handleAvatarError"
            >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
            </el-upload>
          </div>
        </el-col>
      </el-col>
      <el-col :sm="24" style="text-align:center;padding: 10px 0;">
        <div class="bottom_bg"></div>
      </el-col>
    </el-row>
  </el-row>
</template>

<script>
import { findAllArticles } from "@/api/infomaction";
import { axios } from "@/api/axios";
import { mapGetters } from "vuex";
export default {
  computed: {
    //获取左侧单位勾选的id数组 [1,2,3]
    ...mapGetters(["userInfo"]),
  },
  data() {
    return {
      comid: "",
      username: "",
      id: 0,
      saveId: "",
      uploadUrl: "",
      articleData: {},
      companyData: {},
      textVisible: false,
      urlVisble: false,
      titleNode: false,
      upload: false,
      titleNode: false,
      fujianurl: "",
      fjname: "",
    };
  },
  created() {
    this.getParams();
    this.fetchData();
    this.idValue();
  },
  methods: {
    handleClose() {},
    getParams() {
      // 取到路由带过来的参数
      this.comid = this.userInfo.comid;
      this.id = this.$route.query.id;
      this.username = this.userInfo.username;
      this.companyName = this.userInfo.companyName;
      this.uploadUrl = this.VUE_APP_BASE_API + "/common/webupload.shtml";
    },
    async fetchData(pageNo) {
      axios("/admin/file/findAllArticles2.do", "get", {
        articleId: this.id,
      }).then((data) => {
        this.articleData = data.data;
        this.articleData.document = this.$route.query.document;
        console.log(this.articleData);
      });
    },

    //  查看当前的数据
    see() {
      axios("/admin/file/findAllArticles.do", "get", {
        articleId: this.id,
        companyId: this.comid,
      }).then((data) => {
        console.log(data);
        data.data.forEach((e) => {
          if (
            this.username == e.username &&
            this.companyName == e.companyName
          ) {
            console.log(e.id);
            this.saveId = e.id;
            this.saveFuJian();
          }
        });
      });
    },
    async saveFuJian(pageNo) {
      axios("/admin/file/saveFuJian.do", "POST", {
        articlereadId: this.saveId,
        fjName: this.fjname,
        fjUrl: this.fujianurl,
      }).then((data) => {
        if (data.error == "0") {
          this.$message({
            message: "上传成功",
            type: "success",
          });
        } else {
          this.$message.error(data.errorMsg);
        }
      });
    },
    toDocument() {
      window.location.href = this.articleData.fujianurl;
    },
    idValue() {
      if (this.articleData.fujianurl != "") {
        this.urlVisble = true;
      }
      if (this.articleData.textdetails != "") {
        this.textVisible = true;
      }
      if (this.articleData.simpledetails != "") {
        this.titleNode = true;
      }
    },
    // 获取文件URL和文件名
    handleAvatarSuccess(res, file, fileList) {
      this.fujianurl = this.VUE_APP_BASE_API + res.url;
      this.fjname = file.name;
      this.see();

      //   console.log(this.fujianurl);
    },
    // 成功上传后返回
    handleAvatarError(err, file, fileList) {
      this.$message.error("上传失败");
      console.log(err, file, fileList);
      // alert(err, file, fileList)
    },
  },
};
</script>

<style lang="scss" scoped>
.companybook-main {
  margin: 0 auto;
  padding: 10px;
  border-radius: 4px;
  background-color: #fff;
}

.companybook-body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overflow-y: auto;
  background-color: #eef1f6;
  padding: 10px;
}
.xl_fenge {
  width: 100%;
  line-height: 4px;
  height: 4px;
  background: url("../../../assets/xl_fenge.jpg") left top repeat-x;
}
.bottom_bg {
  background: url("../../../assets/bottom_bg.jpg") left top repeat-x;
  height: 45px;
  width: 100%;
}
.textdetails {
  white-space: pre-wrap;
}
.border {
  border-left: 1px solid #b36247;
  border-right: 2px solid #b36247;
}
.el-upload-dragger {
  background-color: rgb(255, 251, 240) !important;
}
.textdetails {
  ::v-deep {
    img {
      width: 100%;
    }
    a {
      color: #0082c5 !important;
    }
  }
}
</style>
